package org.learn2;

/**
 * @Author: 梁二东
 * @Date: 2024/11/20 20:22
 * @Description:
 **/
public class ThreadDemo extends Thread {

    @Override
    public void run() {
        System.out.println("当前线程准备进入休眠,线程名称:" + Thread.currentThread().getName() + ",当前时间:" + System.currentTimeMillis() / 1000);
        try {
            //休眠 2 秒
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("当前线程休眠结束,线程名称:" + Thread.currentThread().getName() + ",当前时间:" + System.currentTimeMillis() / 1000);
    }

    public static void main(String[] args) throws InterruptedException {
        System.out.println("主线程开始运行,线程名称:" + Thread.currentThread().getName() + ",当前时间:" + System.currentTimeMillis() / 1000);
        ThreadDemo threadDemoOne = new ThreadDemo();
        threadDemoOne.start();
        //join 强占 cpu
        threadDemoOne.join();
        System.out.println("主线程结束运行,线程名称:" + Thread.currentThread().getName() + ",当前时间:" + System.currentTimeMillis() / 1000);

    }
}
